package com.yzion.widgetlib.refreshrecyclerview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.internal.InternalAbstract;
import com.yzion.widgetlib.R;

/**
 * 默认刷新头
 * ZJJ
 **/
public class DefaultRefreshHeader extends InternalAbstract implements RefreshHeader {

    private TextView mTvHint;
    private ProgressBar mProgress;

    public static DefaultRefreshHeader newInstance(Context context){
        View wrapper = LayoutInflater.from(context).inflate(R.layout.by_header_refresh_layout,null);
        return new DefaultRefreshHeader(wrapper);
    }

    protected DefaultRefreshHeader(@NonNull View wrapper) {
        super(wrapper);
        mTvHint = wrapper.findViewById(R.id.pull_to_refresh_text);
        mProgress = wrapper.findViewById(R.id.pull_to_refresh_progress);
    }

    @Override
    public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
        super.onStateChanged(refreshLayout, oldState, newState);
    }

    @Override
    public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) {
        mProgress.setVisibility(View.GONE);
        mTvHint.setText("下拉刷新数据");
        return super.onFinish(refreshLayout, success);
    }

    @Override
    public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
        super.onStartAnimator(refreshLayout, height, maxDragHeight);
    }

    @Override
    public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
        super.onReleased(refreshLayout, height, maxDragHeight);
        mTvHint.setText("正在加载数据");
        mProgress.setVisibility(View.VISIBLE);
    }
}
